home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / language / openprlg.sit / Open Prolog 1.0d26 / Open Prolog Extras < prev    next >
Encoding:
Text File  |  1991-12-31  |  6.2 KB  |  151 lines

  1. Some of the useful extra built-in or external predicates
  2. in Open Prolog 1.0d26 are listed below:
  3.  
  4.  
  5. 'system$menu'(set,MenuName,MenuItemName,Enable,Icon,KeyEquivalent).
  6. %always use 'set' for the first argument
  7. %Enter 'enabled'  or 'disabled' or '' in the Enable field.
  8. %Enter Icon Number or 0 in Icon Field
  9. %Enter Keyboard Equivalent in KeyEquivalent Field (only works for a new menu).
  10. 'system$menu' can be used to enable & disable existing menu items.
  11. The system adds 256 to the icon number you provide, if it's not 0.
  12. (Supply your own icons using something like ResEdit.)
  13. example:
  14. 'system$menu'(set,'Trixi','Help',enabled,1,'Y').
  15. When the menu is selected by the user, Open Prolog looks for a clause
  16. with a head of the form:
  17. 'system$menu$hook'(MenuName,MenuItemName)
  18. If it is found, the clause is executed.
  19.  
  20. 'system$alert'(alertMessage1,alertMessage2,alertMessage3,alertMessage4).
  21. %must not be structured terms. They are concatenated & displayed.
  22. 'system$confirm'(message1,message2,message3,message4).
  23. %must not be structured terms. They are concatenated & displayed.
  24. Succeeds or fails depending on Yes or No button.
  25. 'system$predicate'(Name,Term,Kind).
  26. 'system$owner$name'(Name). %used to be 'system$username'(X).
  27. 'system$machine$name'(Name). %System 7.
  28. 'system$seconds'(Seconds). %Since 1/1/1904 - negative but don't worry.
  29. 'system$date'(Seconds,Date). %Seconds is always input
  30. 'system$time'(Seconds,Time). %Seconds is always input
  31. 'system$random'(Range,RandomNumber). %range is always input
  32. %range is 1 to Range, or -1 to Range. Don't ask for Range of -1, 0 or +1.
  33.  
  34. say(Phrase,Volume) needs MacinTalk to work. 
  35. Due to a bug in Macintalk, all other sounds are disabled!
  36. The Phrase must be an atom or a number. 
  37. Pass a Volume of 0 - 7.  A volume of 0 means the current setting
  38. will be used.
  39.  
  40. eg. 
  41. 'system$username'(X),say('Hi',7),say(X,7).
  42.  
  43. macsbug & macsbugFail need Macsbug to work, and will crash otherwise.
  44.  
  45. play(SoundName,Volume) will play any Type 1 'snd ' resource.
  46. Sounds recorded with the new ╘Sound╒ Control Panel Device and 
  47. all the sounds for the System Bell are snds of this type.
  48. To play them, give their names exactly as they appear in
  49. the ╘Sound╒ Control Panel Device.
  50. Be careful to get spacing and punctuation exactly right.
  51. If the sound can't be found, or is too big to fit into memory,
  52. the call will fail,
  53. Pass a Volume of 0 - 7.  A volume of 0 means the current setting
  54. will be used.
  55.  
  56. E.g.
  57. play('Simple Beep',5).
  58.  
  59. The snd resources can be resident in any open window, the Worksheet,
  60. Open Prolog itself, or the System.
  61.  
  62. 'open$prolog$eof$char'(CurrentEofChar,NewEofChar). %default is 26
  63. 'open$prolog$eoln$char'(CurrentEolnChar,NewEolnChar). %default 31
  64.  
  65. 'system$show$about' %Shows the About Open Prolog╔ box
  66.  
  67. 'toolbox$GetIndString'(Atom,ResourceNumber,Index). %same as the Mac
  68. Toolbox GetIndString, where the string is turned into an atom.
  69.  
  70. Window-handling Predicates.
  71.  
  72. A number of predicates have been written to handle window-based I/O.
  73. Please be aware that they are subject to change.
  74.  
  75. Basic Ideas:
  76. ╫    Window Numbers
  77. We use window numbers because
  78. it is not possible to refer to a window by its name. This is because its
  79. name may change, and because (in theory anyway) many windows can
  80. have the same names.
  81. So, every window is assigned a window number when it
  82. is created (distinct from its parameter pointer or file number etc.). 
  83.  
  84. ╫    Starting Pointer & Single-Line-Selection
  85. Whenever text is output
  86. to a window (say using the write command), a pointer, called the
  87. starting pointer, is made point to the next character after the last
  88. character output.
  89.  
  90. When a user selects text using the Enter key, the text selected goes
  91. into a text buffer that is passed to the Prolog interpreter.
  92. In the case of single-line-selection, the 
  93. start of the selection is computed by going from the caret backwards
  94. along the line to the start of the line or to the starting pointer,
  95. whichever comes first. The end of the selection is the end of the line. 
  96.  
  97. ╫ Highlighting & Outlines
  98. It is possible to highlight a particular run of text. Just to confuse you,
  99. the highlight is called an outline, because that's how it started out.
  100. The highlight will 'stick' to the text specified even when text before,
  101. within or after it has been added or removed. Therefore it's not safe to
  102. refer to a highlight by its start & end points, which may vary. Instead, a
  103. highlight is given a unique index number by which it may be referred to
  104. later.
  105.  
  106. ╫    Some Built-Ins
  107.  
  108. 'system$window$open$file$window'(Name,WindowNumber,ResultCode)
  109. A window is opened with the name given (or brought to the front if it's
  110. open already). If a file of the same name exists, then it's opened into the
  111. window if possible. A result code of 0 indicates everything was OK;
  112. anything else means some error occured. It's not an error to not find a
  113. corresponding file.
  114.  
  115. 'system$window$set$starting$point'(WindowNumber,StartingPoint) &
  116. 'system$window$get$starting$point'(WindowNumber,StartingPoint)
  117. These can be used to get and set the starting point. Normally you needn't
  118. bother with these, as the starting point is automatically updated.
  119. Sometimes, however, you 'll need them. For example, say you've written
  120. a parser, and you want to indicate errors to the user in the window.
  121. When you display the error message as appropriate, you'll want to
  122. reset the window environment more or less exactly as is was just before
  123. the error occured. For this, you'll need to get the starting point beforehand,
  124. and then reset it after outputting the error message, etc.
  125. I have a rather complex example, so mail me if you'd like it.
  126.  
  127. 'system$window$front'(WindowNumber)
  128. Tells you which window is at the front.
  129.  
  130. 'system$window$get$output'(WindowNumber).
  131. Tells you which is the current output window.
  132.  
  133. 'system$window$set$output'(WindowNumber,Status).
  134. The designated window becomes the output window. Any error (e.g. if
  135. the window is read-only, etc. will be reported in Status. A Status of 0
  136. means OK.
  137.  
  138. 'system$window$select'(WindowNumber).
  139. Bring the window to the front.
  140.  
  141. 'system$window$get$selection'(WindowNumber,Start,End)
  142. Tells you the selection start and end.
  143.  
  144. 'system$window$set$selection'(WindowNumber,Start,End)
  145. Allows you to set the selection start and end.
  146.  
  147. 'system$window$set$outline'(WindowNumber,StyleNumber,
  148.             Start,End,OutlineReference).
  149. Only a style 1 is defined.
  150.  
  151. 'system$window$clear$outline'(WindowNumber,OutlineReference)